package cn.liulingfengyu.structuralpattern.compositepattern;

/**
 * 组合模式示例
 */
public class CompositePatternDemo {
    public static void main(String[] args) {
        // 创建根节点
        Composite root = new Composite("根节点");

        // 创建子节点
        Composite branch1 = new Composite("分支1");
        Composite branch2 = new Composite("分支2");

        // 创建叶子节点
        Leaf leaf1 = new Leaf("叶子1");
        Leaf leaf2 = new Leaf("叶子2");
        Leaf leaf3 = new Leaf("叶子3");

        // 组装树结构
        root.add(branch1);
        root.add(branch2);

        branch1.add(leaf1);
        branch1.add(leaf2);

        branch2.add(leaf3);

        // 执行操作
        root.operation();
    }
}